(function($) {
    appcan.button("#nav-left", "btn-act",
    function() {});
    appcan.button("#nav-right", "btn-act",
    function() {});

    appcan.ready(function() {
        $.scrollbox($("body")).on("releaseToReload",
        function() { //After Release or call reload function,we reset the bounce
            $("#ScrollContent").trigger("reload", this);
        }).on("onReloading",
        function(a) { //if onreloading status, drag will trigger this event
        }).on("dragToReload",
        function() { //drag over 30% of bounce height,will trigger this event
        }).on("draging",
        function(status) { //on draging, this event will be triggered.
        }).on("release",
        function() { //on draging, this event will be triggered.
        }).on("scrollbottom",
        function() { //on scroll bottom,this event will be triggered.you should get data from server
            $("#ScrollContent").trigger("more", this);
        }).reload();
    })
    appcan.button("#dingwaimai", "btn-act",
    function() {
        var islog = appcan.locStorage.getVal("islog"); // true 为已登录，false 为未登录
        if(islog){
            appcan.window.open({
                name: 'detail',
                data: 'detail.html'
            });
        }
        else{
            appcan.window.alert({
                title: '提示',
                content: '您还未登录，请先登录',
                buttons: '确定',
                callback: function() {
                    appcan.locStorage.setVal("yemian", "index"); //保存页面
                    appcan.window.close(-1);
                    appcan.window.open({
                        name: 'login',
                        data: 'login.html'
                    });
                }
            });
        }
    });
    appcan.button("#location", "btn-act",
    function() {
        showPosition();
    });
    function showPosition(){
        var latlon = 37.870590+','+ 112.548879; // 维度和经度
        // baidu的定位接口
        var url = ' https://api.map.baidu.com/geocoder/v2/?ak=C93b5178d7a8ebdb830b9b557abce78b&location='+latlon+'&output=json&pois=0';
        $.ajax({
            url: url,
            type: 'GET',
            dataType: 'jsonp',
            beforeSend: function(){
                $("#city").text("正在定位...");
            },
            success: function(data){
                $("#city").text(data.result.addressComponent.city);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                $("#city").text("定位失败");
            }
        });
    }
})($);